package com.franklin.java.entity.sql;

import com.franklin.java.utils.ProjectUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Franklin
 * @since 2021/9/26 17:41
 */
public enum JdbcConsoleType {
    DATABASE_TOOL("DatabaseTool"),
    FRANKLIN_JDBC_CONSOLE("FranklinJdbcConsole");

    private String name;

    JdbcConsoleType(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public static JdbcConsoleType of(String name){
        JdbcConsoleType[] values = values();
        for (JdbcConsoleType value : values) {
            if (value.name.equals(name)){
                return value;
            }
        }
        throw new IllegalArgumentException("no type with name : " + name);
    }

    public static List<String> getNames(){
        if (!ProjectUtils.hasDatabaseTool()){
            return Collections.singletonList(FRANKLIN_JDBC_CONSOLE.getName());
        }
        return Arrays.stream(values())
            .map(JdbcConsoleType::getName)
            .collect(Collectors.toList());
    }

    public static JdbcConsoleType getDefault(){
        return ProjectUtils.hasDatabaseTool() ?
            JdbcConsoleType.DATABASE_TOOL :
            JdbcConsoleType.FRANKLIN_JDBC_CONSOLE;
    }
}
